package days4.easy.title66;

/**
 * @Author fengzihao
 * @Date 2024-04-18 19:49
 */
class Solution {
    public int[] plusOne(int[] digits) {
        int i = digits.length - 1;
        for (; i >= 0; i--) {
            if (digits[i]<9){
                digits[i]+=1;
                break;
            }else {
                digits[i] = 0;
            }
        }
        if(i>=0){
            return digits;
        }else{
            int[] newDigits = new int[digits.length+1];
            newDigits[0] = 1;
            System.arraycopy(digits, 0, newDigits, 1, newDigits.length - 1);
            return newDigits;
        }
    }
}
